home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / GRAPHICS / TB_XMODE.ZIP / XMODE.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-07-05  |  7.7 KB  |  194 lines

  1. ;───────────────────────────────────────────────────────────────────────────────
  2. ;
  3. ; This file was intended for learning purposes and it accompanies the package
  4. ; about 320x400x256 xmode made by The Bitripper.
  5. ;
  6. ; You're ofcourse allowed to modify this code as much as you like, but please,
  7. ; when you spread the package, spread it in whole and unmodified, so others
  8. ; don't encounter any problems. Thnx.
  9. ;
  10. ; Also, I'd like to be greeted. Don't bother about it, you don't have to,
  11. ; but it's kinda polite. Then again, who wants to be polite ;) ? Well, see for
  12. ; yarselves. Whatever it'll be, I promise, I won't get mad at you :).
  13. ;
  14. ; Compile with TASM, just start MAKE.EXE.
  15. ;
  16. ; If you don't have MAKE.EXE (shame on you!) then, you can also compile this by
  17. ; typing the following at the command line:
  18. ;
  19. ; TASM /m XMODE.ASM  <─┘
  20. ; TLINK /x XMODE.OBJ <─┘
  21. ;
  22. ; I don't know MASM, so I don't know if it will compile.. Anyway, Borland rulez!
  23. ;
  24. ;───────────────────────────────────────────────────────────────────────────────
  25.  
  26. .MODEL SMALL                                    ; Small memory model is enough
  27.  
  28. .STACK 200h                                     ; Little out of proportion, but
  29.                                                 ; that doesn't matter for now
  30.  
  31.  
  32. .DATA        ;─────────────────────────────────── The DATA segment starts here
  33.  
  34. Crt_C           equ     3d4h                    ; Constants for easily using the
  35. Max_Scan_Line   equ     9h                      ; ports and keeping the source
  36. Underline_Loc   equ     14h                     ; clear and understandable
  37. Mode_Control    equ     17h
  38.  
  39. Seq_C           equ     3c4h
  40. Map_Mask        equ     2h
  41. Memory_Mode     equ     4h
  42.  
  43. Gfx_C           equ     3ceh
  44. Graphics_Mode   equ     5h
  45. Miscellaneous   equ     6h
  46.  
  47. Palette         LABEL   BYTE                    ; Palette of picture to show
  48.                 INCLUDE PALETTE.INC
  49.  
  50. Picture         LABEL   BYTE                    ; Picture to show (it is shown
  51.                 INCLUDE PICTURE.INC             ; two times to show 400 lines)
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58. .CODE        ;─────────────────────────────────── The CODE segment starts here
  59.  
  60. ;───────────────────────────────────────────────────────────────────────────────
  61. ; Use the 'Select' macro to choose a new controller and indexed register.
  62. ;
  63. ; Input  : Controller port adress, Register index number
  64. ; Output : Current value for chosen register in AL
  65. ;───────────────────────────────────────────────────────────────────────────────
  66.  
  67. Select          MACRO   Controller, Register
  68.                 mov     dx,controller           ; Select address register
  69.                 mov     al,register             ; to put register index number
  70.                 out     dx,al
  71.                 inc     dx                      ; Select data register
  72.                 in      al,dx                   ; Input current value to AL
  73.                 ENDM
  74.  
  75. ;───────────────────────────────────────────────────────────────────────────────
  76. ; Use the 'Other' macro to choose another register, indexed through the same
  77. ; controller.
  78. ;
  79. ; Input  : Register index number for current controller
  80. ; Output : Current value for chosen register in AL
  81. ;───────────────────────────────────────────────────────────────────────────────
  82.  
  83. Other           MACRO   Register
  84.                 dec     dx                      ; Select address register
  85.                 mov     al,register             ; to put register index number
  86.                 out     dx,al
  87.                 inc     dx                      ; Select data register
  88.                 in      al,dx                   ; Input current value to AL
  89.                 ENDM
  90.  
  91. ;───────────────────────────────────────────────────────────────────────────────
  92. ; Use the 'Put' macro to set the new value to the chosen register in the chosen
  93. ; controller.
  94. ;
  95. ; Input  : Value to set current register within the current controller in AL
  96. ; Output : none
  97. ;───────────────────────────────────────────────────────────────────────────────
  98.  
  99. Put             MACRO
  100.                 out     dx,al                   ; Save value of AL to register
  101.                 ENDM
  102.  
  103.  
  104.  
  105.  
  106.                 mov     ax,dgroup               ; Initialize DS and ES to
  107.                 mov     ds,ax                   ; datasegment
  108.                 mov     es,ax
  109.  
  110.                 mov     ax,13h                  ; 320x200x256
  111.                 int     10h
  112.  
  113.                 mov     ax,1012h                ; Load palette for picture
  114.                 xor     bx,bx
  115.                 mov     cx,255
  116.                 mov     dx,offset palette
  117.                 int     10h
  118.  
  119.                 select  seq_c,memory_mode
  120.                 and     al,00000011b            ; Clear & preserve lowest 2 bits
  121.                 or      al,00000100b            ; Chain4 & Odd/Even mode off
  122.                 put
  123.  
  124.                 select  gfx_c,graphics_mode     ; Set linear mode
  125.                 and     al,11101111b
  126.                 put
  127.  
  128.                 other   miscellaneous           ; Set linear mode
  129.                 and     al,11111101b
  130.                 put
  131.  
  132.                 select  crt_c,underline_loc     ; Double-word mode off
  133.                 and     al,10111111b
  134.                 put
  135.  
  136.                 other   mode_control            ; Word mode off, byte mode on
  137.                 or      al,01000000b
  138.                 put
  139.  
  140.                 other   max_scan_line           ; 320x400x256
  141.                 and     al,01110000b
  142.                 put
  143.  
  144.                 select  seq_c,map_mask          ; All planes on for writing
  145.                 or      al,00001111b
  146.                 put
  147.  
  148.                 mov     ax,0a000h               ; Set ES to VGA segment (0a000h)
  149.                 mov     es,ax
  150.                 xor     di,di                   ; and DI to offset 0000h
  151.                 mov     cx,08000h               ; The number of words is 32768
  152.                 xor     ax,ax                   ; Put a zero word 32768 times to
  153.                 rep     stosw                   ; ES:DI
  154.  
  155.                 xor     di,di                   ; Start at offset 0000h
  156.  
  157.                 mov     cx,2                    ; Do 2 pictures (200 lines each)
  158. Two_Pictures:   push    cx
  159.  
  160.                 mov     si,offset picture       ; Set source to picture data
  161.                 mov     cx,64000                ; Picture length = 320x200 bytes
  162.  
  163.                 mov     bl,1                    ; Set plane 0 to start at
  164. Do_All_Pixels:  select  seq_c,map_mask          ; Select plane to write to
  165.                 and     al,11110000b
  166.                 or      al,bl
  167.                 put
  168.  
  169.                 movsb                           ; Copy byte from source to
  170.                 dec     di                      ; target and keep offset thesame
  171.  
  172.                 shl     bl,1                    ; Next plane to set pixel to
  173.                 cmp     bl,8                    ; Plane number above 3 ?
  174.                 jna     plane_ok                ; No, it's between plane 0 to 3
  175.                 mov     bl,1                    ; Yes, start at plane 0 again
  176.                 inc     di                      ; Increment the target offset
  177.  
  178. Plane_Ok:       dec     cx                      ; All bytes of picture done ?
  179.                 jnz     do_all_pixels           ; No, do them all
  180.  
  181.                 pop     cx
  182.                 dec     cx                      ; All pictures done ?
  183.                 jnz     two_pictures            ; No, do them all
  184.                 
  185.                 xor     ah,ah                   ; Wait for a keypress
  186.                 int     16h
  187.  
  188.                 mov     ax,3                    ; 80x25x16 text mode
  189.                 int     10h
  190.  
  191.                 mov     ax,4c00h                ; Terminate and back to DOS
  192.                 int     21h
  193. END
  194.